<extend name="Public/base" />

<block name="body"> <script type="text/javascript"
	src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>

<div class="main-title">
	<h2>{:isset($info['id'])?'编辑':'新增'}首页数据</h2>
</div>
<div class="tab-wrap">
	<form action="{:U()}" method="post" class="form-horizontal">
		<div class="form-item">
			<input type="hidden" value="{$info.id}" name="id" /> 
			<label class="item-label">标题<span class="check-tips">（不能为空）</span></label>
			<div class="controls">
				<input type="text" class="text input-large" name="title" value="{$info.title}">
			</div>
		</div>
		<div class="form-item">
				<label class="item-label">位置<span class="check-tips">（不能为空）</span></label>
			<div class="controls">
				<select name="position" title='选择'>
					<option value="1" <eq value="1" name="info['position']">selected='selected'</eq> >1F</option>
					<option value="2" <eq value="2" name="info['position']">selected='selected'</eq> >2F</option>
					<option value="3" <eq value="3" name="info['position']">selected='selected'</eq> >3F</option>
					<option value="4" <eq value="4" name="info['position']">selected='selected'</eq> >4F</option>
					<option value="5" <eq value="5" name="info['position']">selected='selected'</eq> >5F</option>
				</select>
			</div>
		</div>
		<div class="form-item">
			<label class="item-label">排序<span class="check-tips">数字越大
					越靠前</span></label>
			<div class="controls">
				<input name="sort" value="{$info.sort}" class=" text input-small" />
			</div>
		</div>
		<div class="form-item">
			<label class="item-label">广告图片<span class="check-tips"></span></label>

			<div class="controls">
				<input type="file" id="upload_picture_file"> <input
					type="hidden" name="cover_id" id="cover_id"
					value="{$info.cover_id}" />
				<div class="upload-img-box">
					<notempty name="info.cover_id">
					<div class="upload-pre-item">
						<img src="__ROOT__{$info.cover_id|get_cover='path'}" /><span class="btn-close" title="删除图片" onclick="$(this).parent().remove();"></span>
					</div>
					</notempty>
				</div>
			</div>
			<script type="text/javascript">
								//上传图片
							    /* 初始化上传插件 */
								$("#upload_picture_file").uploadify({
							        "height"          : 30,
							        "swf"             : "__STATIC__/uploadify/uploadify.swf",
							        "fileObjName"     : "download",
							        "buttonText"      : "上传图片",
							        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
							        "width"           : 120,
							        'removeTimeout'	  : 1,
							        'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
							        "onUploadSuccess" : uploadPicture_panel,
							        'onFallback' : function() {
							            alert('未检测到兼容版本的Flash.');
							        }
							    });
								function uploadPicture_panel(file, data){
							    	var data = $.parseJSON(data);
							    	var src = '';
							        if(data.status){
							        	$("#cover_id").val(data.id);
							        	src = data.url || '__ROOT__' + data.path
							        	$("#cover_id").parent().find('.upload-img-box').html(
							        		'<div class="upload-pre-item"><img src=" ' + src + '"/></div>'
							        	);
							        } else {
							        	updateAlert(data.info);
							        	setTimeout(function(){
							                $('#top-alert').find('button').click();
							                $(that).removeClass('disabled').prop('disabled',false);
							            },1500);
							        }
							    }
								</script>


		</div>
		<div class="form-item">
			<label class="item-label">绑定商品</label>
			<div class="controls">
				<input type="text" class="text input-4x" id="product" onclick="$(this).val('');" value="{$info.product_id|get_table_field=###,'id','title','product'}"
				 placeholder="商品名称或编号">
				<input type="hidden" name="product_id" value="{$info.product_id}">
			</div>
			<script type="text/javascript">
			$(function($) {
	     		var action = '{:U('Product/product_autocomplete')}';
	     		var input_val = $('input[name="product_id"]');
	     		var products = [];		     		
	     		$('#product').typeahead({
	     			source: function(query, process) {
	     				var parameter = {query: query, d: new Date()};		     				
	     				$.post(action, parameter, function (data) {
	     					products = data;
	     					var results = $.map(products, function (pro) {
	                             return pro.id;
	                         });
	                         process(results);
	     				}, 'json');
	     			},		     			
	     			matcher: function (item) {
	     				return true;
	     			},		     			
	     			highlighter: function (item) {
	     				var pro = [];		     				
	     				$.map(products, function (u) {
	     					if (u.id == item) {
	     						pro = u;
	     					}
	     				});		     				
	     				return pro.title + " (" + pro.id + ")";
	     			},		
	     			updater: function (item) {
	     				input_val.val(item);		     				
	     				var pro = [];		     				
	     				$.map(products, function (u) {
	     					if (u.id == item) {
	     						pro = u;
	     					}
	     				});		     				
	     				return pro.title;
	     			}
	     	   });
	     	});
		</script>
		</div>
		<div class="form-item">
			<input type="hidden" value="{$info.id}" name="id" /> 
			<button class="btn submit-btn ajax-post" id="submit" type="submit"
				target-form="form-horizontal">保存</button>
			<button class="btn btn-return"
				onclick="javascript:history.back(-1);return false;">返 回</button>
		</div>
	</form>
</div>
</block>
<block name="script">
<link rel="stylesheet" type="text/css" href="__STATIC__/bootstrap/css/bootstrap-select.css" />
<link rel="stylesheet" type="text/css" href="__STATIC__/bootstrap/css/bootstrap-typeahead.css" />
<link rel="stylesheet" type="text/css" href="__STATIC__/videojs/css/video-js-5.2.1.css" />
<script type="text/javascript" src="__STATIC__/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="__STATIC__/bootstrap/js/bootstrap-select.js"></script>
<script type="text/javascript" src="__STATIC__/bootstrap/js/bootstrap-typeahead.js"></script>
<script type="text/javascript"
	charset="utf-8">
	showTab();		
	//导航高亮
	highlight_subnav('{:U('index')}');
    Think.setValue('sort', {$info.sort|default=0});
</script> </block>
